<?php
$this->load->view('header');

if (strlen($this->session->flashdata('Error')) > 0) {
    echo '<div class="alert alert-danger alert-dismissable">';
    echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' . $this->session->flashdata('Error') . '</div>';
    $this->session->unset_userdata('Error');
} elseif (strlen($this->session->flashdata('Success')) > 0) {
    echo '<div class="alert alert-success alert-dismissable">';
    echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' . $this->session->flashdata('Success') . '</div>';
    $this->session->unset_userdata('Success');
}
?>

<script type="text/javascript">

    $(document).ready(function() {
        $('#search_by_messenger').select2({
            placeholder: "Select Messenger",
            allowClear: true
        });
    });

    function search_data() {
        $.post("<?= site_url() ?>setup/search_messenger", {
            search_by_messenger: $('#search_by_messenger').val(),
            search_by_status: $('#search_by_status').val(),
            search_by_date: $('#search_by_date').val(),
            search_by_approval: $('#search_by_approval').val()
        },
        function(data) {
            $('#divload').html(data);
        });
    }

    function load_page_messenger(page, ipp) {
        $.post("<?= site_url() ?>setup/load_page_messenger", {
            page: page,
            ipp: ipp,
            search_by_messenger: $('#search_by_messenger').val(),
            search_by_status: $('#search_by_status').val(),
            search_by_date: $('#search_by_date').val(),
            search_by_approval: $('#search_by_approval').val()
        },
        function(data) {
            $('#divload').html(data);
        });
    }

    function add_data() {
        $.post("<?= site_url() ?>setup/add_messenger", function(data) {
            $('#loader').html(data);
        });
    }

    function add_messenger() {
        $.post("<?= site_url() ?>setup/add_messenger_list", function(data) {
            $('#loader').html(data);
        });
    }


</script>
<!--div style="margin-top:20px;"></div-->

<div id="loader" class="container">
    <form class="form-horizontal" id="access" role="form" method="post" action="#">
        <div class="col-md-offset-1">
            <div class="col-md-11">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title"><b class="caret"></b><b> Search Messenger</b></h4>
                    </div>
                    <div class="panel-body">	
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-md-4"><p class="text-left">Messenger</p></label>
                                <div class="col-md-6">
                                    <select name="search_by_messenger" id="search_by_messenger" class="form-control input-sm select2">
                                        <option value="">-- select --</option>
                                        <?php
                                        if (isset($messenger) && !empty($messenger)):
                                            foreach ($messenger as $row_messenger):
                                                echo '<option value="' . $row_messenger['MESSENGER_ID'] . '">' . trim(ucwords($row_messenger['MESSENGER_NAME'])) . '</option>';
                                            endforeach;
                                        endif;
                                        ?>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-4"><p class="text-left">Assign To</p></label>
                                <div class="col-md-6">
                                    <select name="search_by_status" id="search_by_status" class="form-control input-sm select2">
                                        <option value="">-- select --</option>
                                        <option value="Stanby">Active Stanby</option>
                                        <option value="Out">Active Out</option>
                                    </select>
                                </div>
                            </div>
							<div class="form-group">
                                <div class="col-md-4"><label for="button" class="control-label">&nbsp;</label></div>
                                <div class="col-md-3">
                                    <button type="button" class="btn btn-primary btn-sm" onclick="search_data();">Search</button>
                                </div>
                                <div class="col-md-5">
                                    <button type="reset" class="btn btn-default btn-sm">Clear</button>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6 col-md-5">
                            <div class="form-group">
                                <label class="col-md-6"><p class="text-left">Picket Date</p></label>
                                <div class="col-md-6">
                                    <input type="text" class="form-control text-center input-sm" name="search_by_date" id="search_by_date" value="" />
                                </div>
                            </div>		

							<!--div class="form-group">
								<div class="col-sm-6"><label for="picketdate" class="control-label">Picket Date<span style="color:red;">*</span></label></div>
								<div class="col-sm-4">
									<div class="input-group">
										<span class="input-group-addon"><small>From</small></span>
										<input type="text" class="form-control input-sm required special datepicker" id="date1" name="date1" maxlength="10" style="width: 120px;"/>
									</div>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-6"></div>
								<div class="col-sm-4">
									<div class="input-group">			
										<span class="input-group-addon"><small>To</small></span>
										<input type="text" class="form-control input-sm required special datepicker" id="date2" name="date2" maxlength="10" style="width: 120px;"/>
									</div>
								</div>
							</div-->

							
                            <div class="form-group">
                                <label class="col-md-6"><p class="text-left">Approval Status</p></label>
                                <div class="col-md-6">
                                    <select name="search_by_approval" id="search_by_approval" class="form-control input-sm select2">
                                        <option value="">-- select --</option>
                                        <option value="Y">Approved</option>
                                        <option value="N">Not Approved</option>
                                    </select>
                                </div>
                            </div>
                        </div>                        
                    </div>
                </div>

                <div class="panel-body well" id="divload">
                    <div class="col-md-6">
                        <div class="form-group">
                            <div class="col-md-4" style="padding-bottom: 0px;">
                                <button type="button" class="btn btn-success btn-sm" onclick="add_data();">Add Data</button>
                            </div>
                            <div class="col-md-4" style="padding-bottom: 0px;">
                                <button type="button" class="btn btn-success btn-sm" onclick="add_messenger();">Add Messenger</button>
                            </div>
                        </div>
                    </div>
                    <div id="tablecontent" class="col-md-12">						
                        <div class="form-group">
                            <div class="table-responsive">
                                <table class="table table-bordered table-condensed table-striped" style="background:#f9f9f9;">
                                    <thead>
                                        <tr>
                                            <th class="tblhead" style="width:10px;text-align:center;">No</th>
                                            <th class="tblhead" style="width:15px;text-align:center;">Messenger Name</th>
                                            <th class="tblhead" style="width:15px;text-align:center;">Picket Date</th>
                                            <th class="tblhead" style="width:15px;text-align:center;">Assign To</th>
                                            <th class="tblhead" style="width:15px;text-align:center;">Approval Status</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        if (empty($list_data)) {
                                            ?>
                                            <tr><td colspan="8" style="text-align:center">No Data Available</td></tr>
                                            <?php
                                        } else {
                                            foreach ($list_data as $row) {
                                                ?>
                                                <tr>
                                                    <?php
                                                    $messenger_name = $row["MESSENGER_NAME"];
                                                    $messenger_date = $row["TRANS_DATE"];
                                                    $messenger_status = $row["TRANS_STATUS"];
                                                    $messenger_app = $row["TRANS_APP"];

                                                    $status_app = '';
                                                    if ($messenger_app == 'Y') {
                                                        $status_app = '<font color="blue">Approved</font>';
                                                    }

                                                    if ($messenger_app == 'N') {
                                                        $status_app = '<font color="red">Not Approved</font>';
                                                    }
                                                    ?>  

                                                    <td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:center;"><?php echo $row["RECNUM"]; ?>.</td>
                                                    <td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:left;"><?php echo ucfirst($messenger_name); ?></td>
                                                    <td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:center;"><?php echo $messenger_date; ?></td>
                                                    <td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:center;"><?php echo $messenger_status; ?></td>
                                                    <td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:center;"><?php echo $status_app; ?></td>
                                                </tr>
                                                <?php
                                            }
                                        }
                                        ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="form-group">
                            <div id="mypaging">
                                <?php
                                echo $paging;
                                echo $jump_page;
                                echo $ipp;
                                ?>
                            </div>								
                        </div>						
                    </div>
                </div>
            </div>
        </div>
    </form></div>
<!--div style="margin-top:20px;"></div-->
<script>
    $(function() {
        $("input[id^='search_by_date']").datetimepicker({
            scrollInput: false,
            yearOffset: 0,
            lang: 'en',
            timepicker: false,
            datepicker: true,
            format: 'd-m-Y',
            formatDate: 'd/m/Y'
        });
		
		$('#date1').datetimepicker({
			scrollInput: false,
            yearOffset: 0,
            lang: 'en',
            timepicker: false,
            datepicker: true,
            format: 'd/m/Y',
            formatDate: 'd/m/Y'
		});
		
		$('#date2').datetimepicker({
			scrollInput:false,
			closeOnDateSelect:true,
			datepicker:true,
			timepicker:false,
			format:'d/m/Y',
			minDate:'-1970/01/01',
			onGenerate:function( ct ){$(this).find('.xdsoft_date.xdsoft_weekend').addClass('xdsoft_disabled');}
		});
    });
</script>
<?php $this->load->view('footer'); ?>

